home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / netlib / fhopen.c < prev    next >
C/C++ Source or Header  |  1994-04-04  |  2KB  |  92 lines

  1. RCS_ID_C="$Id: fhopen.c,v 1.4 1994/04/04 01:29:06 jraja Exp $";
  2. /*
  3.  * fhopen.c --- open level 1 file from an AmigaDOS file handle
  4.  *
  5.  * Author: jraja <Jarno.Rajahalme@hut.fi>
  6.  *
  7.  * This file is part of the AmiTCP/IP Network Support Library.
  8.  *
  9.  * Copyright © 1994 AmiTCP/IP Group, <amitcp-group@hut.fi>
  10.  *                  Helsinki University of Technology, Finland.
  11.  *                  All rights reserved.
  12.  *
  13.  * Created      : Thu Mar 17 23:57:24 1994 jraja
  14.  * Last modified: Wed Mar 30 10:35:26 1994 jraja
  15.  *
  16.  */
  17.  
  18. #include <ios1.h>
  19. #include <fcntl.h>
  20. #include <stdlib.h>
  21. #include <dos.h>
  22. #include <string.h>
  23. #include <errno.h>
  24. #include <dos/dos.h>
  25. #include <proto/dos.h>
  26.  
  27. #include <bsdsocket.h>
  28.  
  29. extern int (*__closefunc)(int);
  30.  
  31. int
  32. fhopen(long file, int mode)
  33. {
  34.   struct UFB *ufb;
  35.   int         fd;
  36.   int         flags;
  37.  
  38.   /*
  39.    * Set up __closefunc (which is used at cleanup)
  40.    */
  41.   __closefunc = __close;
  42.   /*
  43.    * Check for the break signals
  44.    */
  45.   __chkabort();
  46.   /*
  47.    * find first free ufb
  48.    */
  49.   ufb = __allocufb(&fd);
  50.   if (ufb == NULL)
  51.     return -1; /* errno is set by the __allocufb() */
  52.  
  53.   /*
  54.    * Translate mode to ufb flags
  55.    */
  56.   switch (mode & (O_WRONLY | O_RDWR)) {
  57.   case O_RDONLY:
  58.     if (mode & (O_APPEND | O_CREAT | O_TRUNC | O_EXCL)) {
  59.       errno = EINVAL;
  60.       return -1;
  61.     }
  62.     flags = UFB_RA;
  63.     break;
  64.   case O_WRONLY:
  65.     flags = UFB_WA;
  66.     break;
  67.   case O_RDWR:
  68.     flags = UFB_RA | UFB_WA;
  69.     break;
  70.   default:
  71.     errno = EINVAL;
  72.     return -1;
  73.   }
  74.   if (mode & O_APPEND)
  75.     flags |= UFB_APP;
  76.   if (mode & O_XLATE)
  77.     flags |= UFB_XLAT;
  78.   /*
  79.    * All done!
  80.    */
  81.   ufb->ufbflg = flags;
  82.   ufb->ufbfh = (long)file;
  83.   ufb->ufbfn = NULL;
  84.  
  85. #if 0
  86.   if (Dup2Socket(-1, fd) < 0)    /* mark the fd as used in the AmiTCP's dTable */
  87.     perror("Dup2Socket failed on " __FILE__);
  88. #endif
  89.  
  90.   return fd;
  91. }
  92.